<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-7-14
 * Time: 下午2:56
 */
header("Content-type: text/html; charset=utf-8");
include "/var/www/html/new/d/module/qkxproject/api/des/des.class.php";

$data =$_REQUEST[arg];
$ret_array= simplexml_load_string($data);
$body =$ret_array->Body;
//$body = 'uhfmeQlAZR33oajHrb7t3Tn7W2k/ttl8ULIbuEaN8iHCDXmGAWIXXuZNnk89Qsi0MmVm0Ot7+hoXz8d4uK467M5LeuhGgBeANCNRtBW05cS6Mvo4RWndCYnraL4wa7meEUCOK8Oxift7akuJd2dBSVLpdtS6z5OjWEM0+rAFp8qGjaechE2jIPv820pV0T23O2AFo8IceZN0TmGd8C4xhBAaNwlZyPjQ+5wKTVzYvTXYFt4sSFub/9HY808Ud4aX7OypuyURepEVMkPBglJIxK7jJ113+Ckz2IMxVHUZIfuh6/qUCgIhiZfM3VZtOmbhMDgyYOX+t1yLmUhd+DWRXl2bjt+PbCGe+GszdqphiSEYhn/7RolEBZ6l870e2iWGzVytbEOwr4+wNW+5dlipSPm/9o2h3o05mDKD1Knxq4px2F0V8DmOvPQfhVbnQ30x9f2ZV5DwKndppgbBKLnudoXdOAMGlDnT5ru8OJlT4sxkD1nolTMoUw==';
logfile(date('Y-m-d H:i:s')."---".$body);
if (!class_exists("go_sql")) {
    include("/var/www/html/new/conf/le.je");
    $le = new go_sql();
    $le->connect();
}

$time= time();
$_pid = '13933533445';
$authcode ='24b3f56e1c51e21ce8252fa5';

$a= new Crypt3Des($authcode);

$des = $a->decrypt($body);

$respone_orderid_xml =  simplexml_load_string($des);
$pftorder = (string)$respone_orderid_xml->PartnerId;//票付通订单号
$pftorder_pass= (string)$respone_orderid_xml->IsPassed;//是否通过退票申请

if($pftorder_pass=='true'){
   $str = "update uu_order_fx_details set memo='feicd_refund_success' where orderid=".$pftorder." limit 1";
   $GLOBALS['le']->query($str);
    $status = '100';
    $repMsg = 'success';
}else{
    logfile($pftorder_pass);
    $repMsg ='fail';
    $status = '101';


}
$request = array(
    "RequestCode"=>$_pid,
    "SequenceId"=>$time,
    "Message"=>$repMsg
);
ksort($request);
$other="";
foreach ($request as $k=>$v){
    $other .= strtolower($k)."=".$v."&";
}
$other = substr($other,0,-1);
$_sig = md5($other.$authcode);
$response = <<<XML
<?xml version='1.0'?>
<Response>
  <Head>
    <StatusCode>$status</StatusCode>
    <RequestCode>$_pid</RequestCode>
    <SequenceId>$time</SequenceId>
    <Signed>$_sig</Signed>
    <Message>$repMsg</Message>
  </Head>
</Response>
XML;

echo $response;
function logfile($txt)
{
    $fp = fopen("feicd_refund.txt", "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}